#coding=utf-8
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

'''

获取元素
get_xpath() 传入driver和xpath 返回元素
get_xpath_text() 传入driver和xpath，返回元素的文本
get_xpath_attribute() 传入driver、xpath、attribute，返回元素的属性
get_css()通过css查找元素，返回元素

'''

class getelement():


    def get_xpath(self,driver:webdriver,xpath):

        element = WebDriverWait(driver,10).until(lambda driver:driver.find_element_by_xpath(xpath))

        # element = driver.find_element_by_xpath(xpath)

        return element


    def get_xpath_text(self,driver:webdriver,xpath):

        element = WebDriverWait(driver,10).until(lambda driver:driver.find_element_by_xpath(xpath).text)

        # element = driver.find_element_by_xpath(xpath)

        return element


    def get_xpath_attribute(self,driver:webdriver,xpath,attribute):

        element = WebDriverWait(driver,10).until(lambda driver:driver.find_element_by_xpath(xpath).get_attribute(attribute))

        # element = driver.find_element_by_xpath(xpath).get_attribute(attribute)

        return element


    def get_css(self,driver:webdriver,css):

        element = WebDriverWait(driver,10).until(lambda driver:driver.find_element_by_css_selector(css))

        # element = driver.find_element_by_css_selector(css)

        return element


    def get_xpaths(self,driver:webdriver,xpath):

        elements = WebDriverWait(driver,10).until(lambda driver:driver.find_elements_by_xpath(xpath))

        # elements = driver.find_elements_by_xpath(xpath)

        return elements


    def get_li_text_list(self,driver:webdriver,xpath):

        element = WebDriverWait(driver,10).until(lambda driver:driver.find_element_by_xpath(xpath))

        # elements = driver.find_elements_by_xpath(xpath)

        elements = element.find_elements_by_xpath("li")

        text_list = []

        for li in elements:

            text_list.append(li.text)

        return text_list


    def get_csss(self,driver:webdriver,css):

        elements = WebDriverWait(driver,10).until(lambda driver:driver.find_elements_by_css_selector(css))

        # elements = driver.find_elements_by_css_selector(css)

        return elements

